package middle;

import java.util.Arrays;
import util.PrintUtils;

public class Solution_324 {

    public static void main(String[] args) {
        Solution_324 model = new Solution_324();
//        int[] ints = {1};
//        int[] ints = {2, 1};
        int[] ints = {4, 4, 5, 5, 6};
//        int[] ints = {1,5,1,1,6,4};
//        int[] ints = {1,5,1,1,6};
        model.wiggleSort(ints);
        PrintUtils.arrayInt(ints);
    }

    public void wiggleSort(int[] nums) {
        Arrays.sort(nums);
        int i = (nums.length - 1) / 2, j = nums.length - 1;
        int[] arrays = new int[nums.length];
        System.arraycopy(nums, 0, arrays, 0, nums.length);
        int index = 0;
        while (index < nums.length) {
            nums[index++] = arrays[i--];
            if (index < nums.length) {
                nums[index++] = arrays[j--];
            }
        }
    }
}
